import * as API from '@/services';
import {
  KfBackendEnumPicker,
  DEFAULT_FORM_LAYOUT,
  KfBizQuickFormProps,
  KfFloatingContextProps,
  KfInput,
  KfQuickForm,
  KfTextArea, KfUpload, KfUserPicker,
} from 'kf-web-library';
import {Form} from 'antd';
import React, {FunctionComponent} from 'react';
import HxJournalPicker from "@/components/HxJournalPicker";
import HxJournalPeriodPicker from "@/components/HxJournalPeriodPicker";
import HxJournalColumnPicker from '@/components/HxJournalColumnPicker';
import {Article_SpecialTopicIdModify} from "@/services";
import HxJournalSpecialTopicPicker from "@/components/HxJournalSpecialTopicPicker";

const FormItem = Form.Item;
type ModifyEntity = API.Article_SpecialTopicIdModify;

type DataFormProps = {} & KfBizQuickFormProps & KfFloatingContextProps;

/**
 * 文章 表单
 */
const SpecialTopicQuickForm: FunctionComponent<DataFormProps> = (props) => {
  const {formType, bizId, ...rest} = props;

  return (
    <KfQuickForm
      formType={formType}
      formProps={{
        labelCol: {
          flex: '0 0 100px',
        },
        wrapperCol: {
          flex: '1',
        },
      }}
      defaultQueryRequest={() =>
        API.queryArticle(bizId!).then((resp) => {
          if (resp.flag) {
            resp.data = {
              ...resp.data,
              specialTopicId: resp.data?.specialTopic?.id,
            } as any;
          }
          return new Promise((resolve) => resolve(resp));
        })
      }
      submitRequest={{
        modify: (formValues) => API.modifyArticleSpecialTopicId({specialTopicId: formValues.specialTopicId, articleId: bizId} as ModifyEntity),
      }}
      {...rest}
    >
      <FormItem name={nameof<ModifyEntity>((x) => x.specialTopicId)} label="特殊文章类型" rules={[{required: true}]}>
        <HxJournalSpecialTopicPicker.Select/>
      </FormItem>
    </KfQuickForm>
  );
};

export default SpecialTopicQuickForm;
